﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ZhiAo.Management;
using ECI.SSO.BizEntity;
using ZhiAo.WebLib.Data;

public partial class MsLineDetail : BasePage
{

    protected string pram = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DdlDataBind.BindType(drpType);
            this.txtDate.Text = DateTime.Now.ToString("yyyy-MM-dd");
            LoadData();
        }
        pram = "?pram={0},{1},{2}";
        pram = string.Format(pram, drpType.SelectedValue, base.GetSite, txtDate.Text);

    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        //try
        //{
        LoadData();
        //}
        //catch
        //{

        //}
    }

    private void LoadData()
    {
        string siteName = "";
        string sql = " SELECT STNM FROM SQ_STBPRP_B WHERE YR_STCD = '" + base.GetSite + "'";
        DataTable dtSite = DBHelper.GetDataTable(sql);
        if (dtSite.Rows.Count > 0)
        {
            siteName = dtSite.Rows[0][0].ToString();
        }

        DataTable drData = GetData();

        string thHtml = "";
        thHtml += "<tr>";
        thHtml += "      <td colspan=\"25\"><strong>" + siteName + " 　" + this.txtDate.Text + " 　" + this.drpType.SelectedItem + "　详细信息：</strong></td>";
        thHtml += "</tr>";


        string tbHtml = "<tr><td width=\"10%\"><strong>时间</strong></td>{0}</tr><tr><td><strong>时" + drpType.SelectedItem + "</strong></td>{1}</tr>";
        int a = 0;
        string xs = "";
        string tm = "";
        string dtrn = "";
        if (drData.Rows.Count < 12)
        {
            foreach (DataRow tr in drData.Rows)
            {
                a++;
                string currTM = DateTime.Parse(tr["TM"].ToString()).Hour.ToString() + ":00";
                tm += "<td><strong>" + currTM + "</strong></td>";
                dtrn += "<td>" + tr["DTRN"] + "</td>";

            }
            xs += string.Format(tbHtml, tm, dtrn);
        }
        else
        {
            foreach (DataRow tr in drData.Rows)
            {
                a++;
                string currTM = DateTime.Parse(tr["TM"].ToString()).Hour.ToString() + ":00";
                tm += "<td><strong>" + currTM + "</strong></td>";
                dtrn += "<td>" + tr["DTRN"] + "</td>";
                if (a % 12 == 0)
                {
                    xs += string.Format(tbHtml, tm, dtrn);
                    tm = "";
                    dtrn = "";
                }
            }
        }











        //string tbHtml = "<tr>";
        //tbHtml += "<th width=\"115\">时间</th>";
        //tbHtml += "<th width=\"90\">时" + drpType.SelectedItem.Text + "</th>";
        //tbHtml += "</tr>";
        //foreach (DataRow tr in drData.Rows)
        //{
        //    tbHtml += "<tr>";
        //    tbHtml += "<td>" + DateTime.Parse(tr["TM"].ToString()).ToString("yyyy-MM-dd HH:mm") + "</td>";
        //    tbHtml += "<td>" + tr["DTRN"] + "</td>";
        //    tbHtml += "</tr>";
        //}
        tbData.Text = thHtml + xs;
    }

    private DataTable GetData()
    {
        DataTable dt = new DataTable();
        string type = Request.QueryString["type"];
        string sql = "";
        sql += "EXEC [dbo].[XmlData]";
        sql += "@TYPE = N'{0}',";
        sql += "@SITEID = N'{1}',";
        sql += "@CURRDATE = N'{2}'";
        if (this.txtDate.Text == DateTime.Now.ToString("yyyy-MM-dd"))
        {
            if (DateTime.Now.Hour > 8)
            {
                this.txtDate.Text = DateTime.Today.ToString("yyyy-MM-dd");
            }
            else
            {
                this.txtDate.Text = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd");
            }
        }
        sql = string.Format(sql, this.drpType.SelectedValue, base.GetSite, txtDate.Text + " 08:00:00");
        DataSet ds = DBHelper.GetDataSet(sql);
        if (ds.Tables.Count > 0)
            dt = ds.Tables[0];
        return dt;
    }
}
